<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>余额提现</title>
	<link rel="stylesheet" href="normalize-css/normalize.css">
	<link rel="stylesheet" href="css/style.css">
	<script src="js/zepto.min.js"></script>
</head>
<body>
	<div class="section withdrawals">
		<div class="card">
			<span class="title text-color-1">提现到支付宝账户</span>
			<a  href="withdrawals" style="float:right;font-size:10px;">点击更换提现到银行卡</a>

			<div class="option-item panel">
        <label for="alipayNum">手机号码：</label>
				<input minlength="11" maxlength="11" class="account" name="alipayNum" type="text"/>
			</div>

			<div class="input-item-large">
				<div class="input-item-wrap">
					<label for="price">提现金额</label>
				<span class="price-icon">¥</span>
				<input type="number" name="price" id="price">
				</div>
				<span class="note">最多可提现金额为¥<span class="balance">1200.00</span></span>
			</div>
			<button>提现</button>
		</div>
	</div>
</body>
</html>
<script>
$(document).ready(function(){

	//发出余额提现的post请求，提交参数，支付宝账号account + 金钱数balance
	var withdrawlsURL = "/withdrawls";

	function checkPhone(phone){
    if(!(/^1[34578]\d{9}$/.test(phone))){
        alert("手机号码有误，请重填");
        return false;
    }
		return true;
	}
	$(".balance").text(sessionStorage.balance);
	$("button").click(function(){
		var money = parseInt($("#price").val());
		var account = $(".account").val();
		if(checkPhone(account)){
			if (money<=parseInt(sessionStorage.balance) && money!="") {
				$.post(withdrawlsURL,{
						balance:money,
						account:account
					},function(res){
						alert(res.resultInfo);
				});
			}
			else {
				alert("最多提现"+sessionStorage.balance+"元");
			}
		}
	});
});
</script>
